package com.zyj.benchmark.sample;

import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;

/**
 * 第一个例子
 */
public class Sample_01_HelloWorld {

    //> Task :Sample1.main()
    //# JMH version: 1.33
    //# VM version: JDK 14, OpenJDK 64-Bit Server VM, 14+36-1461
    //# VM invoker: D:\library\jdks\openjdk-14\bin\java.exe
    //# VM options: -Dfile.encoding=UTF-8 -Duser.country=CN -Duser.language=zh -Duser.variant
    //# Blackhole mode: full + dont-inline hint (default, use -Djmh.blackhole.autoDetect=true to auto-detect)
    //# Warmup: 5 iterations, 10 s each
    //# Measurement: 5 iterations, 10 s each
    //# Timeout: 10 min per iteration
    //# Threads: 1 thread, will synchronize iterations
    //# Benchmark mode: Throughput, ops/time
    //# Benchmark: com.zyj.benchmark.Sample1.wellHelloThere
    @Benchmark
    public void wellHelloThere() {
        // this method was intentionally left blank.
    }
//# Run progress: 0.00% complete, ETA 00:01:40
//# Fork: 1 of 1
//# Warmup Iteration   1: 3630398779.756 ops/s
//# Warmup Iteration   2: 3726771451.804 ops/s
//# Warmup Iteration   3: 3890227423.751 ops/s
//# Warmup Iteration   4: 3729002491.555 ops/s
//# Warmup Iteration   5: 3711923831.819 ops/s
//Iteration   1: 3784637393.728 ops/s
//Iteration   2: 3904119743.364 ops/s
//Iteration   3: 3938494000.978 ops/s
//Iteration   4: 3886548559.913 ops/s
//Iteration   5: 3817329432.016 ops/s
//# Run complete. Total time: 00:01:40

    //Benchmark                Mode  Cnt           Score           Error  Units
    //Sample1.wellHelloThere  thrpt    5  3866225826.000 ± 244441451.755  ops/s

    public static void main(String[] args) throws RunnerException {
        Options opt = new OptionsBuilder()
                .include(Sample_01_HelloWorld.class.getSimpleName())
                .forks(1) //设置总共测几轮
//                .mode(Mode.Throughput) //默认是 org.openjdk.jmh.annotations.Mode.Throughput
                .build();

        new Runner(opt).run();
    }
}
